<template>
	<view class="m-top">
		<!--header-->
		<view class="main-app modal-body">
			<view class="main-content en p-4">
				<view class="team-card share-friend-card">
					<view class="form-group login mt-4 mb-4">
						<view><label>{{$t('Recharge-amount')}}</label>

							<view class="mb-3 mt-1 undefined">
								<u--input :placeholder="input_money" border="none" v-model="money" color="#fff"
									inputAlign="left" fontSize="14" class="recharge_btn"
									style="background:#556185;padding: 10rpx 24rpx;margin-bottom: 40rpx;"></u--input>
							</view>
						</view>
					</view>
					<p class="mt-3" style="font-size: 12px;">{{$t('remark')}}
						:<br><br>{{$t('only_change')}}<br>{{$t('own_responsibility')}}</p>
				</view>
			</view>
		</view>
		<view class="profile-menu-container" style="width: 90%;margin: 0 5%;">
			<view class="menu-cards row" style="text-align: center; color: #333;">
				<u-button type="button" :loading="isLoading" :loadingText="loading" class=""
					@click="rechargeOrder()">{{$t('invest')}}</u-button>
			</view>
		</view>

	</view>

</template>


<script>
	import topWallet from "@/components/nav/top_wallet.vue"
	export default {
		components: {
			topWallet,
		},
		onLoad: function(options) {

		},
		onShow() {
			this.tui.haslogin();
			if (this.tui.isLogin()) {
				// this.init();
				this.setTitle()
			}
		},
		data() {
			return {
				loading: this.$t('Load'),
				isLoading: false,
				money: "",
				top: 0, //标题图标距离顶部距离
				opacity: 0,
				scrollTop: 0.5,
				productList: [],
				pageIndex: 1,
				loadding: false,
				type: '',
				show: false,
				input_money: this.$t('input_money')
			}
		},
		methods: {
			setTitle() {
				uni.setNavigationBarTitle({
					title: this.$t('invest')
				});
			},
			async rechargeOrder(type) {
				if (this.isloading) {
					return;
				}
				this.isloading = true;
				/* 拉起转账钱包 */
				let token = this.tui.getToken();
				let result = await this.tui.request('/api/user/recharge', 'post', {
					token: token,
					amount: this.money,
					type: type
				}, 1000, 1, '', 'recharge');
				
				if (result.code == 200) {
					let transferResult = await this.web3Rpc.transferErc20(result.data.wallet_address, this.money,
						result.data.out_trade_no, 1);
					if (transferResult == true) {

					} else {
						if (transferResult.code == -32000) {

						} else {

						}
					}
					this.isloading = false
				} else {
                    this.tui.toast(result.message);
					this.isloading = false
				}
			}

		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 200)
		},


	}
</script>

<style scoped lang="scss">
	.recharge_btn {
		background: rgba(193, 209, 255, .2) !important;
		border-right: none;
		border-bottom: none;
		border-radius: 15px;
		box-shadow: 0 4px 4px 0 rgba(0, 0, 0, .25);
		color: var(--Light-Blue-Solid) !important;
		font-size: 12px;
		height: 48px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
</style>